package com.jcnet.bizaia.fragment;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.os.Process;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.SeekBar;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;

import com.baidu.cyberplayer.core.BVideoView;
import com.baidu.cyberplayer.core.BVideoView.OnCompletionListener;
import com.baidu.cyberplayer.core.BVideoView.OnErrorListener;
import com.baidu.cyberplayer.core.BVideoView.OnInfoListener;
import com.baidu.cyberplayer.core.BVideoView.OnPlayingBufferCacheListener;
import com.baidu.cyberplayer.core.BVideoView.OnPreparedListener;
import com.baidu.cyberplayer.dlna.DLNAActionListener;
import com.baidu.cyberplayer.dlna.DLNAProviderFactory;
import com.jcnet.bizaia.App;
import com.jcnet.bizaia.DLNAControlActivity;
import com.jcnet.bizaia.R;
import com.jcnet.bizaia.VodDetailActivity;
import com.jcnet.bizaia.bean.VodDetailBean;
import com.jcnet.bizaia.tools.MusicTools;
import com.mozillaonline.providers.DownloadManager;
import com.mozillaonline.providers.DownloadManager.Request;
import com.mozillaonline.providers.downloads.DownloadService;
public class JCVideoViewFragment2 extends Fragment implements OnPreparedListener, 
	OnCompletionListener,
	OnErrorListener, 
	OnInfoListener,
	OnPlayingBufferCacheListener
	{
	
	public static final String JC_SETVOD_URL = "JC_SETVOD_URL";
	public static final String JC_DLAN_OK = "JC_DLAN_OK";
	
	private final String TAG = "VideoViewPlayingActivity";
	/**
	 * 您的ak 
	 */
	//private String AK = "";
	/**
	 * //您的sk的前16位
	 */
	//private String SK = "";
		
	//private String mVideoSource = "http://devimages.apple.com/iphone/samples/bipbop/gear4/prog_index.m3u8";
	private String mVideoSource = "http://itstreaming.apple.com/podcasts/atd/D3_Jobs_860x480_6mb.mov";
	
	private BVideoView mVV = null;
	/*private BMediaController mVVCtl = null;
	private RelativeLayout mViewHolder = null;*/
	
	private boolean mIsHwDecode = false;
	
	private EventHandler mEventHandler;
	private HandlerThread mHandlerThread;
	
	private final Object SYNC_Playing = new Object();
		
	private final int EVENT_PLAY = 0;
	
	private final int EVENT_SEEKBAR = 1000000;
	private final int EVENT_PLAY_END = 200000;
	private final int EVENT_PLAYING = 300000;
	
	private WakeLock mWakeLock = null;
	private static final String POWER_LOCK = "VideoViewPlayingActivity";
	
	
	private Timer timer ;
	
	private BroadcastReceiver broadcastReceiver;
	
	private VodDetailBean vodDetailBean ;
	
	private boolean isShwoMenu = true;
	
	DownloadManager mDownloadManager;
	
	/**
	 * 播放状态
	 */
	private  enum PLAYER_STATUS {
		PLAYER_IDLE, PLAYER_PREPARING, PLAYER_PREPARED,
		
		//  停止          播放        暂停
	}
	
	private PLAYER_STATUS mPlayerStatus = PLAYER_STATUS.PLAYER_IDLE;
	
	
	/**
	 * 记录播放位置
	 */
	private int mLastPos = 0;
	
	
	
	private SeekBar seekBar;
	
	
	private TextView timeTotal;
	
	private TextView timeCurrent;
	
	private Handler handler;
	
	

	private ImageButton playButton;    //底部play
	
	private Button popPlayButton;   //中心大的play button


	private ImageButton downloadButton;
	
	
	private LinearLayout controllLayout;
	
	private ImageButton zoomImageButton;
	
	private boolean bigScreen = false;
	
	//DLAN SETTING
	
	private final int UPDATE_INFO = 0;
	private final int GET_RENDER_SUC = 103;
	private final int GET_RENDER_FAIL = 104;
	private final int ENABLE_SUC = 105;
	private final int ENABLE_FAIL = 106;

	private ProgressDialog alertPorgress;
	private AlertDialog selectDialog;
	
	private Handler uiHandler = new Handler() {
		public void handleMessage(Message msg) {
			switch (msg.what) {

			case ENABLE_SUC:
				Toast.makeText(getActivity(), "enable_suc",
						Toast.LENGTH_LONG).show();
				popPlayButton.setEnabled(true);
				break;
			case ENABLE_FAIL:
				Toast.makeText(getActivity(), "enable_dlna_fail",
						Toast.LENGTH_LONG).show();
				break;
			case GET_RENDER_SUC:

				if (alertPorgress != null && alertPorgress.isShowing())
					alertPorgress.dismiss();
				showRenderList();
				break;
			case GET_RENDER_FAIL:

				if (alertPorgress != null && alertPorgress.isShowing())
					alertPorgress.dismiss();
				Toast.makeText(getActivity(), "null renders",
						Toast.LENGTH_LONG).show();
				break;

			default:
				break;
			}
		}
	};
	
	
	
	Handler mUIHandler = new Handler() {
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case UPDATE_INFO:
				//mInfoTV.setText((String) msg.obj);
				
				Toast.makeText(getActivity(), (String) msg.obj, 0).show();
				
				break;
			default:
				break;
			}
		}
	};

	
	
	private void playVideo() {
		
		String source = App.HTTP_PATH+vodDetailBean.getVideourl();
		if (source == null || source.equals("")) {
			setInfo("Please input a valid video path");
		} else {
			getRenderList();
	}
}
	
	
	List<String> renderList;

	private void getRenderList() {
		renderList = DLNAControlActivity.serviceProvider.getRenderList();
		if (renderList == null) {
			uiHandler.sendEmptyMessage(GET_RENDER_FAIL);
			return;
		}
		uiHandler.sendEmptyMessage(GET_RENDER_SUC);
	}
	
	
	
	private void showRenderList() {
		ListView listView = new ListView(getActivity());
		listView.setAdapter(new ArrayAdapter<String>(getActivity(),
				android.R.layout.simple_list_item_1, renderList));
		listView.setBackgroundColor(Color.WHITE);
		listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				selectDialog.dismiss();
				String selectDevice = renderList.get(arg2);

				Intent intent = new Intent(getActivity(),
						DLNAControlActivity.class);
				intent.putExtra("device", selectDevice);
				intent.putExtra("url", App.HTTP_PATH+vodDetailBean.getVideourl());
				getActivity().startActivity(intent);
			}
		});
		selectDialog = new AlertDialog.Builder(getActivity())
				.setView(listView).setCancelable(true).create();
		selectDialog.show();
	}

	
	private void setInfo(String info) {
		Message msg = new Message();
		msg.what = UPDATE_INFO;
		msg.obj = info;
		mUIHandler.sendMessage(msg);
	}
	
	DLNAActionListener mActionListener = new DLNAActionListener() {

		@Override
		public void onStop(boolean isSucess, int errCode, String errDesc) {
			// TODO Auto-generated method stub

		}

		@Override
		public void onSetVolume(boolean isSucess, int errCode, String errDesc) {
			// TODO Auto-generated method stub

		}

		@Override
		public void onSetMute(boolean isSucess, int errCode, String errDesc) {
			// TODO Auto-generated method stub

		}

		@Override
		public void onSetMediaURI(boolean isSucess, int errCode, String errDesc) {
			// TODO Auto-generated method stub

		}

		@Override
		public void onSelectRenderDevice(boolean isSuccess, int errCode,
				String errDesc) {
			// TODO Auto-generated method stub

		}

		@Override
		public void onSeek(boolean isSucess, int errCode, String errDesc) {
			// TODO Auto-generated method stub

		}

		@Override
		public void onPlay(boolean isSucess, int errCode, String errDesc) {
			// TODO Auto-generated method stub

		}

		@Override
		public void onPause(boolean isSucess, int errCode, String errDesc) {
			// TODO Auto-generated method stub

		}

		@Override
		public void onGetVolume(boolean isSucess, int result, int errCode,
				String errDesc) {
			// TODO Auto-generated method stub

		}	

		@Override
		public void onGetSupportedProtocols(boolean isSucess, String result,
				int errCode, String errDesc) {
			// TODO Auto-generated method stub

		}

		@Override
		public void onGetMute(boolean isSucess, boolean result, int errCode,
				String errDesc) {
			// TODO Auto-generated method stub

		}

		@Override
		public void onEnableDLNA(boolean isSuccess, int errCode, String errDesc) {
			// TODO Auto-generated method stub
			if (isSuccess)
				uiHandler.sendEmptyMessage(ENABLE_SUC);
			else {
				uiHandler.sendEmptyMessage(ENABLE_FAIL);
			}
		}

		@Override
		public void onDisableDLNA(boolean isSuccess, int errCode, String errDesc) {
			// TODO Auto-generated method stub

		}

	};

	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		//DLAN  setting
		
		DLNAControlActivity.serviceProvider = DLNAProviderFactory.getProviderInstance(getActivity());
		if (DLNAControlActivity.serviceProvider == null){
			
		}else{
		//使用您在百度开发者中心上申请的AK,SK
		DLNAControlActivity.serviceProvider.initialize(App.BAIDU_AK, App.BAIDU_SK);
		DLNAControlActivity.serviceProvider.addActionCallBack(mActionListener);
		DLNAControlActivity.serviceProvider.enableDLNA();
		}
		
		
		// TODO Auto-generated method stub
		mDownloadManager = new DownloadManager(getActivity().getContentResolver(),
				getActivity().getPackageName());

		startDownloadService();
		
		View view = View.inflate(getActivity(), R.layout.controllerplaying2, null);
		
		zoomImageButton = (ImageButton)view.findViewById(R.id.zoomButton);
		
		controllLayout = (LinearLayout)view.findViewById(R.id.controllLin);
		
		downloadButton = (ImageButton) view.findViewById(R.id.downloadButton);
		
		playButton = (ImageButton) view.findViewById(R.id.play_btn);
		
		popPlayButton = (Button)view.findViewById(R.id.playButton);
		
		
		seekBar = (SeekBar)view.findViewById(R.id.media_progress);
		
		
		
		downloadButton.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				 Uri srcUri = Uri.parse(App.HTTP_PATH+vodDetailBean.getVideourl());
					DownloadManager.Request request = new Request(srcUri);
					/**
					 * context
					 * file path
					 * file name
					 */
					request.setDestinationInExternalFilesDir(getActivity(),App.DOWNLOAD_VOD_PATH, "/");
					request.setDescription("dwonloading...");
					mDownloadManager.enqueue(request);
			}
		});
		
		
		playButton.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
				switch (mPlayerStatus) {
				
				case PLAYER_PREPARING:  //播放状态
					cancleTimer();
					mVV.pause();
					playButton.setImageResource(R.drawable.play_btn_style);
					mPlayerStatus = PLAYER_STATUS.PLAYER_PREPARED;
					break;
				case PLAYER_PREPARED:  //暂停状态
					//继续播放
					startTimer();
					mVV.resume();
					playButton.setImageResource(R.drawable.pause_btn_style);
					mPlayerStatus = PLAYER_STATUS.PLAYER_PREPARING;
				case PLAYER_IDLE:
					startTimer();
					mEventHandler.sendEmptyMessage(EVENT_PLAY);	
					break;
				default:
					break;
				}
				
				
			}
		});
		
		
		popPlayButton.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				playVideo();
				
			}
		});
		
		zoomImageButton.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if(bigScreen){
					getActivity().sendBroadcast(new Intent(VodDetailActivity.SMAIL_SCREEN));
					zoomImageButton.setImageResource(R.drawable.zoom_big_bg);
				}else{
					getActivity().sendBroadcast(new Intent(VodDetailActivity.BIG_SCREEN));
					zoomImageButton.setImageResource(R.drawable.zoom_smail_bg);
					
				}
				bigScreen = !bigScreen;
			}
		});
		
		seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
			
			@Override
			public void onStopTrackingTouch(SeekBar seekBar) {
				// TODO Auto-generated method stub
				
				mVV.seekTo(seekBar.getProgress());
				seekBar.setProgress(seekBar.getProgress());
				
				mVV.resume();
			}
			
			@Override
			public void onStartTrackingTouch(SeekBar seekBar) {
				// TODO Auto-generated method stub
				mVV.pause();
			}
			
			@Override
			public void onProgressChanged(SeekBar seekBar, int progress,
					boolean fromUser) {
				// TODO Auto-generated method stub
				
				timeCurrent.setText( MusicTools.getFomatTime(progress));
				
			}
		});
		
		mVV = (BVideoView) view.findViewById(R.id.video_view);
		
		timeCurrent = (TextView)view.findViewById(R.id.time_current);
		
		timeTotal = (TextView)view.findViewById(R.id.time_total);
		
		
		PowerManager pm = (PowerManager) getActivity().getSystemService(Context.POWER_SERVICE);
		mWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, POWER_LOCK);
		
		mIsHwDecode = getActivity().getIntent().getBooleanExtra("isHW", false);
		Uri uriPath = getActivity().getIntent().getData();
		if (null != uriPath) {
			String scheme = uriPath.getScheme();
			if (null != scheme) {
				mVideoSource = uriPath.toString();
			} else {
				mVideoSource = uriPath.getPath();
			}
		}
		
		/**
		 * 设置ak及sk的前16位
		 */
		BVideoView.setAKSK("wxQysuQ7aSPfKnwfnCNXogyL", "m7lxadW1eAWU2vHohxlkof2VTx1aWOOP");
		
		/**
		 * 注册listener
		 */
		mVV.setOnPreparedListener(this);
		mVV.setOnCompletionListener(this);
		mVV.setOnErrorListener(this);
		mVV.setOnInfoListener(this);
		
		mVV.setDecodeMode(BVideoView.DECODE_SW);
		mVV.setVideoScalingMode(BVideoView.VIDEO_SCALING_MODE_SCALE_TO_FIT);
		mVV.setOnCompletionListener(new OnCompletionListener() {
			
			@Override
			public void onCompletion() {
				// TODO Auto-generated method stub
				mVV.stopPlayback();
				
				mPlayerStatus = PLAYER_STATUS.PLAYER_IDLE;
				if(timer!=null){
					timer.cancel();
					timer = null;
					mLastPos = 0;
				}
				handler.sendEmptyMessage(EVENT_PLAY_END);
				//playButton.setImageResource(R.drawable.play_btn_style);
			}
		});
		mVV.setOnPreparedListener(new OnPreparedListener() {
			
			@Override
			public void onPrepared() {
				// TODO Auto-generated method stub
				
				if(timer!=null){
					startTimer();
					}
			}
		});
		
		mVV.setOnTouchListener(new OnTouchListener() {
			
			@Override
			public boolean onTouch(View v, MotionEvent event) {
				// TODO Auto-generated method stub
				if(isShwoMenu){
					controllLayout.setVisibility(View.GONE);
					getActivity().sendBroadcast(new Intent(VodDetailActivity.CLOSE_MENU));
				}else{
					controllLayout.setVisibility(View.VISIBLE);
					getActivity().sendBroadcast(new Intent(VodDetailActivity.OPEN_MENU));
				}
				isShwoMenu = !isShwoMenu;
				
				return false;
			}
		});
		
		/**
		 * 开启后台事件处理线程
		 */
		mHandlerThread = new HandlerThread("event handler thread",
				Process.THREAD_PRIORITY_BACKGROUND);
		mHandlerThread.start();
		mEventHandler = new EventHandler(mHandlerThread.getLooper());
		
		
		timer = new Timer();
		
		
		
		
		handler = new Handler(){
			@Override
			public void handleMessage(Message msg) {
				// TODO Auto-generated method stub
				super.handleMessage(msg);
				switch (msg.what) {
				case EVENT_SEEKBAR:
					if(mVV.isPlaying()){
						seekBar.setMax(mVV.getDuration());
						seekBar.setProgress(mVV.getCurrentPosition());
						
						timeCurrent.setText( MusicTools.getFomatTime(mVV.getCurrentPosition()));
						timeTotal.setText(MusicTools.getFomatTime(mVV.getDuration()));
					
					}
					
					break;
				case EVENT_PLAY_END:
					playButton.setImageResource(R.drawable.play_btn_style);
					
					System.out.println("1111111111111");
				break;
				
				case EVENT_PLAYING:
					playButton.setImageResource(R.drawable.pause_btn_style);
					System.out.println("2222222222");
					break;
				default:
					break;
				}
			}
		};
		
		
		
		
		return view;
	}
	
	
	
	
	
	
	
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		
		broadcastReceiver = new BroadcastReceiver() {
			
			@Override
			public void onReceive(Context context, Intent intent) {
				// TODO Auto-generated method stub
				
				if(intent.getAction().equals(JC_SETVOD_URL)){  //接受传递的播放地址
					
				
					vodDetailBean = (VodDetailBean) intent.getSerializableExtra("vodDetailBean");
					
					mVideoSource = App.HTTP_PATH+vodDetailBean.getVideourl();
					mEventHandler.sendEmptyMessage(EVENT_PLAY);	
					System.out.println("videoUrl="+mVideoSource);
				}
				
				if(intent.getAction().equals(JC_DLAN_OK)){
					playVideo();     //开始检测DLAN
				}
			}
		};
		IntentFilter intentFilter = new IntentFilter();
		intentFilter.addAction(JC_SETVOD_URL);
		intentFilter.addAction(JC_DLAN_OK);
		getActivity().registerReceiver(broadcastReceiver, intentFilter);
		
		
		
	}
	
	class EventHandler extends Handler {
		public EventHandler(Looper looper) {
			super(looper);
		}

		@Override
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case EVENT_PLAY:
				/**
				 * 如果已经播放了，等待上一次播放结束
				 */
				if (mPlayerStatus != PLAYER_STATUS.PLAYER_IDLE) {
					synchronized (SYNC_Playing) {
						try {
							SYNC_Playing.wait();
							Log.v(TAG, "wait player status to idle");
						} catch (InterruptedException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}
				}

				/**
				 * 设置播放url
				 */
				mVV.setVideoPath(mVideoSource);
				
				/**
				 * 续播，如果需要如此
				 */
				if (mLastPos > 0) {

					mVV.seekTo(mLastPos);
					mLastPos = 0;
				}

				/**
				 * 显示或者隐藏缓冲提示 
				 */
				mVV.showCacheInfo(true);
				
				/**
				 * 开始播放
				 */
				mVV.start();

				mPlayerStatus = PLAYER_STATUS.PLAYER_PREPARING;
				
				
				handler.sendEmptyMessage(EVENT_PLAYING);
				
				break;
			default:
				break;
			}
		}
	}
	
	
			
	
	public void changeZoonButton(){
		bigScreen = false;
		zoomImageButton.setImageResource(R.drawable.zoom_big_bg);
	}
	

	

	
	@Override
	public void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		Log.v(TAG, "onPause");
		/**
		 * 在停止播放前 你可以先记录当前播放的位置,以便以后可以续播
		 */
		if (mPlayerStatus == PLAYER_STATUS.PLAYER_PREPARED) {
			mLastPos = mVV.getCurrentPosition();
			mVV.stopPlayback();
			
		}
	}

	
	
	
	public JCVideoViewFragment2() {
		super();
		// TODO Auto-generated constructor stub
	}

	
	@Override
	public void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		Log.v(TAG, "onResume");
		if (null != mWakeLock && (!mWakeLock.isHeld())) {
			mWakeLock.acquire();
		}
		/**
		 * 发起一次播放任务,当然您不一定要在这发起
		 */
		//mEventHandler.sendEmptyMessage(EVENT_PLAY);	
	}
	
	@Override
	public void onStop(){
		super.onStop();
		Log.v(TAG, "onStop");
	}
	
	@Override
	public void onDestroy(){
		super.onDestroy();
		/**
		 * 结束后台事件处理线程
		 */
		mHandlerThread.quit();
		Log.v(TAG, "onDestroy");
	}

	@Override
	public boolean onInfo(int what, int extra) {
		// TODO Auto-generated method stub
		switch(what){
		/**
		 * 开始缓冲
		 */
		case BVideoView.MEDIA_INFO_BUFFERING_START:
			break;
		/**
		 * 结束缓冲
		 */
		case BVideoView.MEDIA_INFO_BUFFERING_END:
			break;
		default:
			break;
		}
		return false;
	}
	
	/**
	 * 当前缓冲的百分比， 可以配合onInfo中的开始缓冲和结束缓冲来显示百分比到界面
	 */
	@Override
	public void onPlayingBufferCache(int percent) {
		// TODO Auto-generated method stub
		
	}	

	/**
	 * 播放出错
	 */
	@Override
	public boolean onError(int what, int extra) {
		// TODO Auto-generated method stub
		Log.v(TAG, "onError");
		synchronized (SYNC_Playing) {
			SYNC_Playing.notify();
		}
		mPlayerStatus = PLAYER_STATUS.PLAYER_IDLE;
		return true;
	}

	/**
	 * 播放完成
	 */
	@Override
	public void onCompletion() {
		// TODO Auto-generated method stub
		Log.v(TAG, "onCompletion");
		
		synchronized (SYNC_Playing) {
			SYNC_Playing.notify();
		}
		mPlayerStatus = PLAYER_STATUS.PLAYER_IDLE;
	}

	/**
	 * 播放准备就绪
	 */
	@Override
	public void onPrepared() {
		// TODO Auto-generated method stub
		Log.v(TAG, "onPrepared");				
		mPlayerStatus = PLAYER_STATUS.PLAYER_PREPARED;
	}


	
	 public void cancleTimer(){
		 if(timer!=null){
			 timer.cancel();
			 timer = null;
		 }
	 }
	 
	 public void startTimer(){
		 timer = new Timer();
		 timer.schedule(new TimerTask() {
				
				@Override
				public void run() {
					// TODO Auto-generated method stub
					handler.sendEmptyMessage(EVENT_SEEKBAR);	
				}
			}, 1000,1000);
	 }
	 
	 @Override
	public void onDestroyView() {
		// TODO Auto-generated method stub
		super.onDestroyView();
		
		getActivity().unregisterReceiver(broadcastReceiver);
		
		if (DLNAControlActivity.serviceProvider != null)
			DLNAControlActivity.serviceProvider.disableDLNA();
		
		if(timer!=null){
			timer.cancel();
			timer = null;
		}
	}
	 
	 private void startDownloadService() {
			Intent intent = new Intent();
			intent.setClass(getActivity(), DownloadService.class);
			getActivity().startService(intent);
		}
}
